<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script type="text/javascript" src="/js/plugins/form/jquery.form.js"></script>
    <script>
        $(function () {
            var judge = 1;
            //获取装载数据的input框
            var currentInput = $("#currentPage");
            var currentInput2 = $("#currentPage2");
            //创建用于存储游记的数组
            var travelArr = [];
            var travelArr2 = [];
            //总页数
            var pages = 1;
            var pages2 = 1;
            //当前页为第一页
            // currentInput.val(1);

            //获取游记数据的方法
            function query() {
                //获取当前页的值
                var currentPage = currentInput.val();
                $.get('/travels', {currentPage: currentPage}, function (data) {
                    //合并两个数组到第一个参数数组上
                    $.merge(travelArr, data.list);
                    //用于渲染时循环,循环时是取list的属性出来
                    var json = {
                        list: travelArr
                    };
                    //渲染数据
                    $("#allTravels").renderValues(json, {
                        getHref: function (item, value) {
                            console.log(value);
                            //item是当前要渲染数据的元素(a),value就是render-key获取的值
                            //获取要跳转的地址
                            var href = $(item).data("href");
                            //把id拼接进去,再设置到a连接的href属性上
                            $(item).attr('href', href + value);
                        },getHref1:getHref,
                    });
                    //设置总页数
                    pages = data.pages;
                });
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1);
            }

            //默认查询第一页的数据
            query();

            //当页面滚动条变化时，执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height() - 1) {
                    var currentPage = currentInput.val();
                    //判断是否小于或等于最后一页,如果是就去查询
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了!',
                            autoClose: 500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });

            //获取5条每月推荐
            $.get('/travels/commends', {type: 2, pageSize: 3}, function (data) {
                $("#travelsCommends").renderValues(data, {
                    getHref: function (item, value) {
                        //获取要跳转的地址
                        var href = $(item).data("href");
                        //把id拼接进去,再设置到a连接的href属性上
                        $(item).attr('href', href + value);
                    }
                });
                //设置第一个item添加active类
                $(".carousel-item:first").addClass("active");
            });


            $("#sousuo").click(function () {
                judge = 2;
                currentInput2.val(1);
                pages2 = 1;
                travelArr2 = [];
                travel();
                travelpaging();
            });
            function travel() {
                var currentPage = currentInput2.val();
                $("#editForm input[name='currentPage']").val(currentPage);
                $("#editForm").ajaxSubmit(function (data) {
                    $.merge(travelArr2, data.result.list);
                    //用于渲染时循环,循环时是取list的属性出来
                    var json = {
                        list: travelArr2
                    };
                    if(data.success){
                        if (json.list.length != 0) {
                            $("#headline").html("全部游记")
                        }else{
                            $("#headline").html("无相关游记")
                        }
                        $("#allTravels").renderValues(json, {
                            getHref: function (item, value) {

                                //item是当前要渲染数据的元素(a),value就是render-key获取的值
                                //获取要跳转的地址
                                var href = $(item).data("href");
                                //把id拼接进去,再设置到a连接的href属性上
                                $(item).attr('href', href + value);
                            }
                        });
                    }
                    //设置总页数
                    pages2 = data.result.pages
                });
                //当前页input框+1
                currentInput2.val(parseInt(currentPage) + 1);
            }
            function travelpaging() {
                $(window).scroll(function () {
                    if ($(document).scrollTop() + $(window).height() >= $(document).height()-1) {
                        var currentPage2 = currentInput2.val();
                        if (judge == 2) {
                            if (currentPage2 <= pages2) {
                                travel();
                            } else {
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '已经到底了!',
                                    autoClose: 500,
                                    position: 'bottom'  // center: 居中; bottom: 底部
                                });
                                //$("#deletetext").val("");
                            }
                        }
                    }
                })
            }
        });
    </script>
</head>

<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="/index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-20">
            <form id="editForm" method="post" action="/travels/selecttravelbyid">
                <input type="hidden" name="currentPage">
                <div class="input-group-sm ">
                    <input type="text" placeholder="搜游记" class="glyphicon-search" name="text">
                    <a href="javascript:" class="btn btn-default btn-sm">
                        <span class="glyphicon glyphicon-plus btn-sm" id="sousuo">搜索</span>
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>

<input type="hidden" name="currentPage" id="currentPage" value="1">
<input type="hidden" name="currentPage2" id="currentPage2" value="1">

<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list">
                <div class="carousel-item">
                    <div class="border commend">
                        <a data-href="travelContent.html?id=" render-key="list.travel_id" render-fun="getHref">
                            <img render-src="list.coverUrl" width="100%" height="200px">
                            <h1 render-html="list.title"></h1>
                            <small render-html="list.subTitle"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container" id="allTravels2">
    <h6 id="headline">全部游记</h6>
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a data-href="travelContent.html?id=" render-key="list.id" render-fun="getHref">
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <a data-href="/mine/userProfiles.html?id=" render-key="list.author.id" render-fun="getHref1">
                            <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span> </a> 在
                        <span class="addr" render-html="list.place.name"></span>

                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span>0</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a data-href="travelContent.html?id=" render-key="list.id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>